/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.input;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Vector;

/**
 *
 * @author Jacob Morgan
 */
public class InputState {
    public static int mouseX;
    public static int mouseY;
    public static int mouseClickX;
    public static int mouseClickY;
    public static int pmouseX;
    public static int pmouseY;
    public static int mouseButton;
    public static int pmouseButton;
    public static int lastMouseButton;
    private static int mouseWheelRotation = 0;
    public static final List<Integer> pressedKeyCodes = Collections.synchronizedList(new ArrayList<Integer>(32));
    public static final List<Integer> newKeyCodes = Collections.synchronizedList(new ArrayList<Integer>(32));
    public static final List<Integer> releasedKeyCodes = Collections.synchronizedList(new ArrayList<Integer>(32));
    public static int isMouseClicked()
    {
        if(pmouseButton == 0 && mouseButton > 0)
            return mouseButton;
        return 0;
    }
    public static void addKey(int k)
    {
        synchronized(pressedKeyCodes)
        {
            if(!pressedKeyCodes.contains(k))
            {
                pressedKeyCodes.add(k);
                newKeyCodes.add(k);
            }
        }
    }
    public static void removeNewKey(int k)
    {
        newKeyCodes.remove(new Integer(k));
    }
    public static List<Integer> getNewKeys()
    {
        return newKeyCodes;
    }
    public static void removeKey(int c)
    {
        synchronized(pressedKeyCodes)
        {
            pressedKeyCodes.remove(new Integer(c));
        }
        synchronized(releasedKeyCodes)
        {
            releasedKeyCodes.add(new Integer(c));
        }
    }
    public static List<Integer> getKeys()
    {
        return pressedKeyCodes;
    }
    public static void clearRKeys()
    {
        releasedKeyCodes.clear();
    }
    public static void clearNewKeys()
    {
        newKeyCodes.clear();
    }
    public static List<Integer> getRKeys()
    {
        return releasedKeyCodes;
    }
    public static void mouseWheelMoved(int wheelRotation)
    {
        mouseWheelRotation += wheelRotation;
    }
    public static int getMouseWheelRotation()
    {
        int r = mouseWheelRotation;
        mouseWheelRotation = 0;
        return r;
    }
}
